<template>
  <BasicModal v-bind="$attrs" @register="registerModal" destroyOnClose :title="title" @ok="handleSubmit" defaultFullscreen>
    <!-- <BasicForm @register="registerForm"></BasicForm> -->
    <div style="display: flex; flex-direction: row">
      <BasicTable ref="basicTable" @register="registerTable" style="font-size: 12px; padding: 10px"></BasicTable>
    </div>
  </BasicModal>
</template>
<script lang="ts" setup>
  import { ref, computed, unref } from 'vue';
  import { BasicModal, useModalInner } from '/@/components/Modal';
  import { useI18n } from '/@/hooks/web/useI18n';
  import { BasicTable } from '/@/components/Table';
  import { useListPage } from '/@/hooks/system/useListPage';
  import { detailColumns } from '../inventoryProfit.data';
  const { t } = useI18n('common');
  // Emits声明
  const emit = defineEmits(['register', 'success']);
  const isUpdate = ref(true);
  //表格
  const { tableContext } = useListPage({
    tableProps: {
      title: '资产分类',
      columns: detailColumns,
      canResize: false,
      useSearchForm: false,
      showActionColumn: false,
      formConfig: {
        labelWidth: 60,
        autoSubmitOnEnter: true,
        showAdvancedButton: true,
        fieldMapToNumber: [],
        fieldMapToTime: [],
      },
      actionColumn: {
        width: 60,
        fixed: 'right',
      },
    },
  });
  const [registerTable] = tableContext;
  const basicTable = ref<InstanceType<typeof BasicTable>>();
  const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
    //重置表单
    // await resetFields();
    setModalProps({ confirmLoading: false, showCancelBtn: !!data?.showFooter, showOkBtn: !!data?.showFooter });
    isUpdate.value = !!data?.isUpdate;
    if (unref(isUpdate)) {
    }
  });
  //设置标题
  const title = computed(() => (!unref(isUpdate) ? t('addText') : t('editText')));
  //表单提交事件
  async function handleSubmit(_v) {
    try {
      setModalProps({ confirmLoading: true });
      //关闭弹窗
      closeModal();
      //刷新列表
      emit('success');
    } finally {
      setModalProps({ confirmLoading: false });
    }
  }
</script>
